home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Dragonsmith 1.1.1 / CW 4.5 Update / TrapUtils.cp < prev   
Encoding:
Text File  |  1994-07-04  |  2.2 KB  |  75 lines  |  [TEXT/MMCC]

  1. /*
  2.     TrapUtils.c
  3.     
  4.     OS and Toolbox trap-related utility functions.  Adapted from code in Inside Macintosh Volume VI, pages 3–8 to 3–9
  5.     
  6.     Created    17 Sep 1992    TrapAvailable and its static "herlper" functions
  7.     Modified    01 Jul 1994 by Francis H Schiffer, 3rd - to use UPPs
  8.  
  9.     Copyright © 1992 by Paul M. Hoffman
  10.     Send comments or suggestions to paul.hoffman@umich.edu -or- dragonsmith@umich.edu
  11.     
  12.     This source code may be freely used, altered, and distributed in any way as long as:
  13.         1.    It is GIVEN away rather than sold (except as expressly permitted by the author)
  14.         2.    This statement and the above copyright notice are left intact.
  15.     
  16. */
  17.  
  18. #include    "TrapUtils.h"
  19. #include    <Traps.h>
  20.  
  21. static short NumToolboxTraps (void);
  22. static UniversalProcPtr AA6EAddress (void);                  /* fhs 1994 july 1 */
  23. static UniversalProcPtr UnimplementedTrapAddress (void);    /* fhs 1994 july 1 */
  24. static TrapType GetTrapType (short trapWord);
  25.  
  26.     
  27. Boolean TrapAvailable (short theTrap)
  28. {
  29.     TrapType        type;
  30.     
  31.     type = GetTrapType (theTrap);
  32.     if (type == ToolTrap) {
  33.         theTrap &= 0x07FF;
  34.         if (theTrap >= NumToolboxTraps ())
  35.             return FALSE;
  36.     }
  37.     return (NGetTrapAddress (theTrap, type) != UnimplementedTrapAddress ());
  38. }
  39.  
  40. static short NumToolboxTraps (void)
  41. {    
  42.     static short    NUM_TBX_TRAPS = -1;        // Initialize NUM_TBX_TRAPS to a nonsensical value
  43.  
  44.     if (NUM_TBX_TRAPS == -1)
  45.         NUM_TBX_TRAPS = ((NGetTrapAddress (_InitGraf, ToolTrap) == AA6EAddress ()) ? 0x0200 : 0x0400);
  46.         
  47.     return NUM_TBX_TRAPS;
  48. }
  49.  
  50. static UniversalProcPtr AA6EAddress (void)
  51. {  /* fhs 1994 July 01 - to use UniversalProcPtrs */
  52.     static UniversalProcPtr    AA6E_ADDR = NULL;            // Initialize _AA6E_ADDR to a nonsensical value
  53.     
  54.     if (AA6E_ADDR == NULL)
  55.         AA6E_ADDR = NGetTrapAddress (0xAA6E, ToolTrap);
  56.         
  57.     return AA6E_ADDR;
  58. }
  59.  
  60. static UniversalProcPtr UnimplementedTrapAddress (void)
  61. {  /* fhs 1994 July 01 - to use UniversalProcPtrs */
  62.     static UniversalProcPtr    UNIMP_TRAP_ADDR = NULL;    // // Initialize UNIMP_TRAP_ADDR to a nonsensical value
  63.     
  64.     if (UNIMP_TRAP_ADDR == NULL)
  65.         UNIMP_TRAP_ADDR = NGetTrapAddress (_Unimplemented, ToolTrap);
  66.         
  67.     return UNIMP_TRAP_ADDR;
  68. }
  69.  
  70. static TrapType GetTrapType (short trapWord)
  71. {
  72.     return (trapWord & 0x0800) ? ToolTrap : OSTrap;
  73. }
  74.  
  75.